<template>
  <div class="app-container">
    <el-button
          type="primary"
          icon="el-icon-search"
          @click="open1"
          size="mini"
          >人员选择</el-button
        >
        <PeopleSelect
          ref="peopleSelect"
          :type="'multiple'"
          :isCheck="true"
          :open="peopleOpen"
          @cancel="peopleOpen = false"
          @submit="submitPeople"
        ></PeopleSelect>
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="open2"
          size="mini"
          >部门选择</el-button
        >
        <DepartmentDialog
          ref="peopleSelect"
          :type="'multiple'"
          :isCheck="true"
          :open="peopleOpen1"
          @cancel="peopleOpen1 = false"
          @submit="submitPeople1"
        ></DepartmentDialog>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
      class="el-forms"
    >
      <div class="handle_box_content" ref="handle_box_content">
        <!-- <el-form-item label="外键" prop="refId">
        <el-input
          v-model="queryParams.refId"
          placeholder="请输入外键"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
        <el-form-item label="项目id" prop="projectId">
          <el-input
            v-model="queryParams.projectId"
            placeholder="请输入项目id"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="项目名称" prop="projectName">
          <el-input
            v-model="queryParams.projectName"
            placeholder="请输入项目名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <!-- <el-form-item label="类别" prop="SORT">
        <el-input
          v-model="queryParams.SORT"
          placeholder="请输入类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
        <!-- <el-form-item label="批次编号" prop="batchCode">
        <el-input
          v-model="queryParams.batchCode"
          placeholder="请输入批次编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
        <el-form-item label="器具名称" prop="toolName">
          <el-input
            v-model="queryParams.toolName"
            placeholder="请输入器具名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <!-- <el-form-item label="种类序列号" prop="kindNumber">
        <el-input
          v-model="queryParams.kindNumber"
          placeholder="请输入种类序列号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
        <el-form-item label="制造厂家" prop="FACTORY">
          <el-input
            v-model="queryParams.FACTORY"
            placeholder="请输入制造厂家"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="保管负责人" prop="custodyPerson">
          <el-input
            v-model="queryParams.custodyPerson"
            placeholder="请输入保管负责人"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <!-- <el-form-item label="开始时间" prop="startTime">
        <el-date-picker clearable
                        v-model="queryParams.startTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker clearable
                        v-model="queryParams.endTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择结束时间">
        </el-date-picker>
      </el-form-item> -->
        <el-form-item label="管理责任人" prop="managePerson">
          <el-input
            v-model="queryParams.managePerson"
            placeholder="请输入管理责任人"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="检验结果" prop="results">
          <el-input
            v-model="queryParams.results"
            placeholder="请输入检验结果"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <!-- <el-form-item label="检验日期" prop="inspectDate">
        <el-date-picker clearable
                        v-model="queryParams.inspectDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择检验日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="下次检验日期" prop="nextInspectDate">
        <el-date-picker clearable
                        v-model="queryParams.nextInspectDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择下次检验日期">
        </el-date-picker>
      </el-form-item> -->
        <!-- <el-form-item label="备注" prop="REMARK">
        <el-input
          v-model="queryParams.REMARK"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      </div>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          plain
          size="mini"
          :icon="Showbox ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
          @click="handleShow"
          >{{ Showbox ? "隐藏" : "展开" }}</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:manger:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:manger:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:manger:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:manger:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="mangerList"
      @selection-change="handleSelectionChange"
      @row-click="handleRowClick"
      ref="table"
      border
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="项目名称" align="center" width="130" prop="projectName" sortable/>
      <el-table-column label="器具名称" align="center" prop="toolName" />
      <el-table-column label="制造厂家" align="center" prop="factory" />
      <el-table-column label="保管负责人" align="center" prop="custodyPerson" />
      <el-table-column
        label="开始时间"
        align="center"
        prop="startTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="结束时间"
        align="center"
        prop="endTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="管理责任人" align="center" prop="managePerson" />
      <el-table-column label="检验结果" align="center" prop="results" />
      <el-table-column
        label="检验日期"
        align="center"
        prop="inspectDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.inspectDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="下次检验日期"
        align="center"
        prop="nextInspectDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.nextInspectDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="附件信息" align="center" prop="FILE" />
      <el-table-column
        label="操作"
        align="center"
        width="150"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:manger:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:manger:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listManger,
  getManger,
  delManger,
  addManger,
  updateManger,
} from "@/api/system/manger";
import PeopleSelect from "../../../components/Selection/index.vue"
import DepartmentDialog from "../../../components/DepartmentDialog/index.vue"
export default {
  name: "Manger",
  dicts: ["sys_normal_disable"],
  components: {
    PeopleSelect,
    DepartmentDialog
  },
  data() {
    return {
      // 按钮loading
      // buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工器具管理表格数据
      mangerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        refId: undefined,
        projectId: undefined,
        projectName: undefined,
        SORT: undefined,
        batchCode: undefined,
        toolName: undefined,
        kindNumber: undefined,
        TYPE: undefined,
        FACTORY: undefined,
        custodyPerson: undefined,
        startTime: undefined,
        endTime: undefined,
        managePerson: undefined,
        RESULTS: undefined,
        inspectDate: undefined,
        nextInspectDate: undefined,
        REMARK: undefined,
        FILE: undefined,
      },
      // 表单参数
      form: {},
      Showbox:false,
      peopleOpen:false,
      peopleOpen1:false,
      // 表单校验
      rules: {
        ID: [{ required: true, message: "主键id不能为空", trigger: "blur" }],
        refId: [{ required: true, message: "外键不能为空", trigger: "blur" }],
        projectId: [
          { required: true, message: "项目id不能为空", trigger: "blur" },
        ],
        projectName: [
          { required: true, message: "项目名称不能为空", trigger: "blur" },
        ],
        SORT: [{ required: true, message: "类别不能为空", trigger: "blur" }],
        batchCode: [
          { required: true, message: "批次编号不能为空", trigger: "blur" },
        ],
        toolName: [
          { required: true, message: "器具名称不能为空", trigger: "blur" },
        ],
        kindNumber: [
          { required: true, message: "种类序列号不能为空", trigger: "blur" },
        ],
        TYPE: [{ required: true, message: "型号不能为空", trigger: "change" }],
        FACTORY: [
          { required: true, message: "制造厂家不能为空", trigger: "blur" },
        ],
        custodyPerson: [
          { required: true, message: "保管负责人不能为空", trigger: "blur" },
        ],
        startTime: [
          { required: true, message: "开始时间不能为空", trigger: "blur" },
        ],
        endTime: [
          { required: true, message: "结束时间不能为空", trigger: "blur" },
        ],
        managePerson: [
          { required: true, message: "管理责任人不能为空", trigger: "blur" },
        ],
        RESULTS: [
          { required: true, message: "检验结果不能为空", trigger: "blur" },
        ],
        inspectDate: [
          { required: true, message: "检验日期不能为空", trigger: "blur" },
        ],
        nextInspectDate: [
          { required: true, message: "下次检验日期不能为空", trigger: "blur" },
        ],
        REMARK: [{ required: true, message: "备注不能为空", trigger: "blur" }],
        FILE: [
          { required: true, message: "附件信息不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    open1() {
      this.peopleOpen = true;
    },
    open2() {
      this.peopleOpen1 = true;
    },
    //选择人的确定按钮事件 submitPeople(nikeNamelist)方法传参一个默认接收用户昵称数组   submitPeople(peopleList,nikeNamelist)方法传参两个则是接收用户昵称数组和用户账号数组
    submitPeople(peopleList) {
      //console.log(peopleList);

      this.peopleOpen = false;
    },
    submitPeople1(peopleList) {
      //console.log(peopleList);
      this.peopleOpen1 = false;
    },
     handleRowClick(row) {
      this.$refs.table.toggleRowSelection(row);
    },
    handleShow() {
      this.Showbox = !this.Showbox
      const element = this.$refs.handle_box_content;
      if(this.Showbox){
        element.style.overflow = 'visible';
        element.style.height = 'fit-content'
      }else {
        element.style.overflow = 'hidden';
        element.style.height = '50px'
      }
    },
    /** 查询工器具管理列表 */
    getList() {
      this.loading = true;
      listManger(this.queryParams).then((response) => {
        this.mangerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ID: undefined,
        refId: undefined,
        projectId: undefined,
        projectName: undefined,
        SORT: undefined,
        batchCode: undefined,
        toolName: undefined,
        kindNumber: undefined,
        TYPE: undefined,
        FACTORY: undefined,
        custodyPerson: undefined,
        startTime: undefined,
        endTime: undefined,
        managePerson: undefined,
        RESULTS: undefined,
        inspectDate: undefined,
        nextInspectDate: undefined,
        REMARK: undefined,
        FILE: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({
        path: "/Admission/formDialog",
        query: {title:"新增工器具管理" },
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.loading = true;
      this.reset();
      const ID = row.id || this.ids;
      getManger(ID).then((response) => {
        // this.loading = false;
        // this.form = response.data;
        // this.open = true;
        // this.title = "修改工器具管理";
      });

      this.$router.push({
        path: "/Admission/formDialog",
        query: { ID:ID,title:"修改工器具管理",flowId:1 },
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          // this.buttonLoading = true;
          if (this.form.ID != null) {
            updateManger(this.form)
              .then((response) => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              })
              .finally(() => {
                // this.buttonLoading = false;
              });
          } else {
            addManger(this.form)
              .then((response) => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              })
              .finally(() => {
                // this.buttonLoading = false;
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const IDs = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除工器具管理编号为"' + IDs + '"的数据项？')
        .then(() => {
          this.loading = true;
          return delManger(IDs);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/manger/export",
        {
          ...this.queryParams,
        },
        `manger_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style>
.handle_box_content {
  width: 81%;
  height: 50px;
  overflow: hidden;
}
.el-forms{
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
}
</style>
